#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <ctime>

#include "bubbleSort.h"

using std::rand;
using std::srand;
using std::time;


BubbleSort::BubbleSort( int size )
{
    _size = ( size > 0 ? size : 10 );
    srand( time( 0 ) );

    for( int i = 0; i < _size; i++ )
        _data.push_back( 1 + rand() % 100 );
}

void BubbleSort::sortVector()
{
    int temp;

    for( int i = 0; i < _size; i++ )
    {
        int j = i + 1;
        for( ; j < _size; j++ )
        {
            if( _data[j] < _data[i] )
            {
                temp = _data[i];
                _data[i] = _data[j];
                _data[j] = temp;
            }
        }
    }
}

void BubbleSort::printVector()
{
    std::cout << "[ ";
    for( int i = 0; i < _size; i++ )
    {
        std::cout << std::setw(2) << _data[i] << " ";
    }
    std::cout << "]" << std::endl;
}


